package com.vieewer.btdemo.view.brightness

import android.media.AudioManager
import android.media.MediaPlayer
import android.media.RingtoneManager
import android.os.Bundle
import android.widget.SeekBar
import com.vieewer.btdemo.R
import com.vieewer.btdemo.base.BaseActivity
import kotlinx.android.synthetic.main.activity_setting_volume.*

class VolumeActivity : BaseActivity() {

    //调节系统音量相关
    private var mAudioManager: AudioManager? = null
    private var mVolumeProgress = 7


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_setting_volume)
        initVolume()
    }


    private fun initVolume() {
        mAudioManager = getSystemService(AUDIO_SERVICE) as AudioManager
        //系统最大音量为15
        sbSystemVolume.max = mAudioManager!!.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
        //current = am.getStreamVolume(AudioManager.STREAM_MUSIC);
        mAudioManager!!.setStreamVolume(AudioManager.STREAM_MUSIC, mVolumeProgress, AudioManager.FLAG_PLAY_SOUND)
        sbSystemVolume.progress = mVolumeProgress
        txt_volume.text = "" + mVolumeProgress
        val notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
        val r = RingtoneManager.getRingtone(applicationContext, notification)

        sbSystemVolume.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
                mVolumeProgress = progress
                txt_volume.text = "" + progress
                mAudioManager!!.setStreamVolume(AudioManager.STREAM_NOTIFICATION, mVolumeProgress, AudioManager.FLAG_PLAY_SOUND)
                r.play()
            }

            override fun onStartTrackingTouch(seekBar: SeekBar) {

            }

            override fun onStopTrackingTouch(seekBar: SeekBar) {
  /*              var data = SystemSettingsBean()
                data.sys_type = SystemSettingsBean.SYS_TYPE_VOLUME
                data.progress = mVolumeProgress
                CommunicateToGlassesHelper.instance.write(JSON.toJSONString(data))*/

            }
        })


    }




}